using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows;

using System.Windows.Shapes;
using System.Windows.Media;

namespace Orbifold.Trefoil
{
    /// <summary>
    /// This static class manages the various popups that are shown in the menu
    /// </summary>
    static class PopuManager
    {

        /// <summary>
        /// the ColorPopup field
        /// </summary>
        private static ColorPopupTool mColorPopup = new ColorPopupTool();
        /// <summary>
        /// Gets or sets the ColorPopup
        /// </summary>
        public static ColorPopupTool ColorPopup
        {
            get { return mColorPopup; }
        }



        /// <summary>
        /// Tool that allows the user to choose a color.
        /// </summary>
        public class ColorPopupTool : ToolBase
        {
            #region Fields
            #endregion

            #region Properties
            /// <summary>
            /// the PopupControl field
            /// </summary>
            private PopupColorPicker mPopupControl;
            /// <summary>
            /// Gets or sets the ColorPopup
            /// </summary>
            public PopupColorPicker PopupControl
            {
                get { return mPopupControl; }
                set { mPopupControl = value;
                value.PopupClosed += new EventHandler<ColorEventArgs>(PopupClosedHandler);
                }
            }

            void PopupClosedHandler(object sender, ColorEventArgs e)
            {
                
            }

            #endregion

            #region Constructor
            ///<summary>
            ///Default constructor
            ///</summary>
            public ColorPopupTool()
                : base("Color tool")
            {
                
            }
            #endregion

            #region Methods

            /// <summary>
            /// Function to execute the command.
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            public override void OnExecute(object sender, ExecutedRoutedEventArgs e)
            {
                if (PopuManager.ColorPopup.PopupControl != null)
                {
                    PopuManager.ColorPopup.PopupControl.ShowPopup();
                   
                }
            }

            #endregion

          



            #region ChangeColorCommand
            /// <summary>
            /// Change color ICommand encapsulation. Note that you need to have a Connectable in order to change the color. The class will not raise an exception however if applied to something else.
            /// </summary>
            class ChangeColorCommand : ICommand
            {
                #region Fields
                private Color mOldColor, mNewColor;

                #region Properties
                /// <summary>
                /// Gets or sets the new color.
                /// </summary>
                /// <value>The new color.</value>
                public Color NewColor
                {
                    get { return mNewColor; }
                    set { mNewColor = value; }
                }

                /// <summary>
                /// Gets or sets the old color.
                /// </summary>
                /// <value>The old color.</value>
                public Color OldColor
                {
                    get { return mOldColor; }
                    set { mOldColor = value; }
                }
                #endregion
                private UIElement mShape;
                #endregion

                #region Constructor
                ///<summary>
                ///Default constructor
                ///</summary>
                public ChangeColorCommand(UIElement shape, Color newColor)
                {
                    if (shape == null)
                        throw new ArgumentException("Changing the color of 'null' is not possible.");
                    mShape = shape;

                    mNewColor = newColor;
                }
                #endregion


                #region ICommand Members

                public void Undo()
                {
                   
                }

                public void Redo()
                {
                   
                }

                public string Text
                {
                    get
                    {
                        return "Change color";
                    }
                    set
                    {
                        throw new Exception("The method or operation is not implemented.");
                    }
                }

                #endregion
            }
            #endregion
        }
    }
}
